<?php /* @var $this Controller */ ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="language" content="en" />

    <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->theme->baseUrl; ?>/css/styles.css" />

	<title><?php echo CHtml::encode($this->pageTitle); ?></title>

	<?php Yii::app()->bootstrap->register(); ?>
</head>

<body>

<!--?php $this->widget('bootstrap.widgets.TbNavbar',array(
    'items'=>array(
        array(
            'class'=>'bootstrap.widgets.TbMenu',
            'items'=>array(
                // array('label'=>'Home', 'url'=>array('/site/index')),
                // array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),
                // array('label'=>'Contact', 'url'=>array('/site/contact')),
                // array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),
                // array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)
            	array('label'=>'Admin', 'url'=>'#', 'items'=>array(
            		array('label'=>'Wewenang', 'url'=>'#'),
            		array('label'=>'Backup', 'url'=>'#'),
            	)),
            	array('label'=>'Pendataan/Pendaftaran', 'url'=>'#', 'items'=>array(
            		array('label'=>'Data Pasar', 'url'=>'#', 'items'=>array(
            			array('label'=>'Pendataan Pasar', 'url'=>'#'),
            			array('label'=>'Inpres Pasar', 'url'=>'#'),
            			array('label'=>'Fasilitas Umum', 'url'=>'#'),
            			array('label'=>'Sewa Tanah', 'url'=>'#'),
            		)),
            		array('label'=>'Data Kios', 'url'=>'#'),
            		array('label'=>'Data PKL', 'url'=>'#', 'items'=>array(
            			array('label'=>'Pendataan PKL', 'url'=>'#'),
            			array('label'=>'TDU PKL', 'url'=>'#'),
            		)),
            		array('label'=>'Data Los', 'url'=>'#'),
            		array('label'=>'Data Pedagang', 'url'=>'#'),
            	)),
            	array('label'=>'Penetapan', 'url'=>'#', 'items'=>array(
            		array('label'=>'Retribusi Minimal', 'url'=>'#'),
            		array('label'=>'Penetapan dan Pencetakan Massal', 'url'=>'#'),
            		array('label'=>'Tanda Terima', 'url'=>'#'),
            	)),
            	array('label'=>'Target Retribusi', 'url'=>'#'),
            	array('label'=>'Penagihan', 'url'=>'#', 'items'=>array(
            		array('label'=>'Surat Permintaan Pembayaran', 'url'=>'#'),
            		array('label'=>'Surat Perintah Membayar', 'url'=>'#'),
            	)),
            	array('label'=>'Pembayaran', 'url'=>'#', 'items'=>array(
            		array('label'=>'Surat Tanda Bukti Penerimaan', 'url'=>'#'),
            		array('label'=>'Surat Tanda Setoran', 'url'=>'#'),
            		array('label'=>'Laporan Pembayaran', 'url'=>'#'),
            	)),
            	array('label'=>'Pelayanan', 'url'=>'#', 'items'=>array(
            		array('label'=>'Cetak Tanda Setoran', 'url'=>'#'),
            		array('label'=>'Retribusi dan Kompensasi', 'url'=>'#'),
            		array('label'=>'Input Permohonan', 'url'=>'#'),
            		array('label'=>'Pengurangan', 'url'=>'#'),
            		array('label'=>'Cetak File Keluaran', 'url'=>'#'),
            	)),
            	array('label'=>'GIS', 'url'=>'#'),
            	array('label'=>'Referensi', 'url'=>'#'),
            ),
        ),
    ),
)); ?-->

<?php
        $menuGroup = 1;

        if(!Yii::app()->user->isGuest){
            $usrSec = Sysusrsecurity::model()->find('CredentialName="'.Yii::app()->user->name.'" and isLocked = 0 and expiredDate > "'.Date('Y-m-d').'"');
            $menuGroup = $usrSec->MenuGroupID;
        }
        
        $menuItems=array();
        if(isset($menuGroup)){
            $appmenu = Appmenu::model()->findAll(array('condition'=>'MenuGroupID = '.$menuGroup.' and isActive = 1','order'=>'MenuSequence asc, InterfaceParentID asc, InterfaceID asc'));
            $items = array(array());
            $itemsURL = array(array());
            $arrInt = array();

            $idxInt = 0;
            while(count($arrInt) < count($appmenu)){
                for($i=0;$i<count($appmenu);$i++){
                    //$moduleID = $appmenu[$i]->ModuleID;
                    $moduleName = $appmenu[$i]->module->ModuleName;
                    $moduleURL = $appmenu[$i]->module->URL;
                    //$moduleURL = '#';
                    //$parInterfaceID = isset($appmenu[$i]->InterfaceParentID)?$appmenu[$i]->InterfaceParentID:NULL;
                    $parInterfaceName = isset($appmenu[$i]->InterfaceParentID)?$appmenu[$i]->interfaceParent->interface->InterfaceName:NULL;
                    //$parInterfaceURL = isset($appmenu[$i]->InterfaceParentID)?$appmenu[$i]->interfaceParent->interface->URL:NULL;
                    //$interfaceID = $appmenu[$i]->InterfaceID;
                    $interfaceName = $appmenu[$i]->interface->InterfaceName;
                    $interfaceURL = $appmenu[$i]->interface->URL;
                    $ShowModuleOnly = $appmenu[$i]->ShowModuleOnly;

                    if(!in_array($interfaceName, $arrInt)){
                        if($parInterfaceName==NULL){
                            if($ShowModuleOnly){
                                $items[$idxInt] = array($moduleName);
                                $itemsURL[$idxInt] = array($moduleURL);
                            }else{
                                $items[$idxInt] = array($moduleName, $interfaceName);
                                $itemsURL[$idxInt] = array($moduleURL, $interfaceURL);
                            }
                            $idxInt+=1;
                            if(!in_array($interfaceName, $arrInt)){
                                array_push($arrInt, $interfaceName);
                            }
                        }else{
                            if(in_array($parInterfaceName, $arrInt)){
                                $c=0;
                                while($c<count($items)){
                                    if(in_array($parInterfaceName, $items[$c]) ){
                                        $arr=array();
                                        $arrURL=array();
                                        $arr=$items[$c];
                                        $arrURL=$itemsURL[$c];
                                        array_push($arr, $interfaceName);
                                        array_push($arrURL, $interfaceURL);
                                        $items[$idxInt]= $arr;
                                        $itemsURL[$idxInt]= $arrURL;
                                        $idxInt+=1;
                                        if(!in_array($interfaceName, $arrInt)){
                                            array_push($arrInt, $interfaceName);
                                        }
                                        break;
                                    }                    
                                   $c+=1;
                                }
                            }else{
                                continue;
                            }
                        }
                    }
                }
            }

            for($i=0;$i<count($items);$i++){
                $com='';
                for($a=0;$a<count($items[$i]);$a++){
                    $value = $items[$i][$a];
                    if($a<=0){
                        $com.='["'.$value.'"]';
                    }else{
                        $com.='["items"]["'.$value.'"]';
                    }
                    $exe = '$menuItems'.$com.'["label"]="'.$items[$i][$a].'";';
                    eval($exe);
                    $exeURL = '$menuItems'.$com.'["url"]="'.Yii::app()->getBaseURL().'/'.$itemsURL[$i][$a].'";';
                    eval($exeURL);

                    $intID = Appapplicationinterfaces::model()->find('InterfaceName="'.$value.'"');
                    if(isset($intID)){
                        $apmen = Appmenu::model()->find('InterfaceID = '.$intID->InterfaceID.' and MenuGroupID = '.$menuGroup.' and isActive = 1');
                        $otherAtt = $apmen->OtherAttributes;
                        $modName = $apmen->module->ModuleName;

                        if(count(explode('=>', $otherAtt))>1){
                            if(count(explode(',', $otherAtt))>1){
                                foreach (explode(',', $otherAtt) as $str){
                                    if (count(explode('=>', $str))>1){
                                        $arr = explode('=>', $str);
                                        $arr[0] = str_replace("'", '', $arr[0]);
                                        $exeAtt = '$menuItems'.$com.'[\''.$arr[0].'\']='.$arr[1].';';
                                        eval($exeAtt);
                                        $exeAttModule = '$menuItems["'.$modName.'"][\''.$arr[0].'\']='.$arr[1].';';
                                        eval($exeAttModule);
                                    }
                                }
                            }else{
                                $arr = explode('=>', $otherAtt);
                                $arr[0] = str_replace("'", '', $arr[0]);
                                $exeAtt = '$menuItems'.$com.'[\''.$arr[0].'\']='.$arr[1].';';
                                eval($exeAtt);
                                $exeAttModule = '$menuItems["'.$modName.'"][\''.$arr[0].'\']='.$arr[1].';';
                                eval($exeAttModule);
                            }
                        }
                    }
                }
            };
        }
        //var_dump($menuItems);
        
        $this->widget('bootstrap.widgets.TbNavbar',array(
            'items'=>array(
                array(
                    'class'=>'bootstrap.widgets.TbMenu',
                    'items'=>$menuItems
                    )
                )
            )
        );
    ?>

<div class="container" id="page">

	<?php if(isset($this->breadcrumbs)):?>
		<?php $this->widget('bootstrap.widgets.TbBreadcrumbs', array(
			'links'=>$this->breadcrumbs,
		)); ?><!-- breadcrumbs -->
	<?php endif?>

	<?php echo $content; ?>

	<div class="clear"></div>

	<div id="footer">
		Copyright &copy; <?php echo date('Y'); ?> by My Company.<br/>
		All Rights Reserved.<br/>
		<?php echo Yii::powered(); ?>
	</div><!-- footer -->

</div><!-- page -->

</body>
</html>
